import com.scurity.User

class BootStrap {
	def springSecurityService
    def init = { servletContext ->
		
		createAdminUserIfRequired()
    }
    def destroy = {
		
    }
	void createAdminUserIfRequired() {
		if (!User.findByUsername("admin")) {
			println "Fresh Database. Creating ADMIN user."
			def encodedPassword = springSecurityService.encodePassword("secret")
			def user = new User(username: "admin",
				password: encodedPassword, enabled:true, eMail:"test@test.com").save()
			
		} else {
			println "Existing admin user, skipping creation"
		}
	}
}
